package com.lfnyxy.service.imp;

import com.lfnyxy.dao.BannerDao;
import com.lfnyxy.entity.BannerEntity;
import com.lfnyxy.query.BannerQuery;
import com.lfnyxy.service.BannerService;
import com.lfnyxy.vo.BannerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BannerServiceImp implements BannerService {
    @Autowired
    public BannerDao bannerDao;

    public int CreateItem(BannerEntity entity) {
        if (entity != null) {
            return bannerDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(BannerEntity entity) {
        if (entity != null) {
            return bannerDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List <BannerVo> QueryPageList(BannerQuery query) {
        int count = bannerDao.QueryPageListCount(query);
        query.setTotal(count);
        return bannerDao.QueryPageList(query);
    }

    public List <BannerEntity> QueryAll() {
        return bannerDao.QueryAll();
    }

    public BannerEntity QueryItem(int Id) {
        if (Id > 0) {
            return bannerDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return bannerDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(BannerEntity entity) {
        if (entity != null) {
            return bannerDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}